package web.admin;

import org.apache.wicket.Component;
import org.apache.wicket.PageParameters;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.IModel;
import web.commons.LogOffLink;

public abstract class AdminBasePage extends WebPage {

    public abstract IModel getPageTitle();

    public abstract IModel getDescription();

    public abstract IModel getKeywords();

    protected abstract Component newTopMenuPanel(String id);

    protected abstract Component newLeftColumnPanel(String id);


    @Override
    protected void onBeforeRender() {
        // add the <title> tag
        addOrReplace(new Label("title", getPageTitle()));

        Label desc = new Label("description", "");
        desc.add(new AttributeAppender("content", getDescription(), " "));
        addOrReplace(desc);

        Label keywords = new Label("keywords", "");
        keywords.add(new AttributeAppender("content", getKeywords(), " "));
        addOrReplace(keywords);

        if (get("top") == null) {
            // subclass-driven components not yet initilized
            addOrReplace(newTopMenuPanel("top"));
        }
        if (get("left") == null) {
            // subclass-driven components not yet initilized
            addOrReplace(newLeftColumnPanel("left"));
        }

        if (get("feedback") == null) {
            // subclass-driven components not yet initilized
            addOrReplace(new FeedbackPanel("feedback"));
        }

        /** cascades the call to its children */
        super.onBeforeRender();
    }

    public AdminBasePage() {
        super();
//        add(new TinyMceInitBehavior());
//        }));new HeaderContributor(new IHeaderContributor() {
//            public void renderHead(IHeaderResponse response) {
//                response.renderJavascriptReference(TinyMCESettings.javaScriptReference());
//            }
//        }));
        add(new AdminLeftMenuPanel("links"));
        add(new LogOffLink("logoff"));


    }

    public AdminBasePage(PageParameters params) {
        this();
    }
}

